package com.lemon.funplus.cheanh;

import yuku.ambilwarna.AmbilWarnaDialog;
import yuku.ambilwarna.AmbilWarnaDialog.OnAmbilWarnaListener;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.lemon.funplus.CheAnhActivity;
import com.lemon.funplus.R;
import com.lemon.funplus.ulti.BaseEngine;

public class TrollSelectDialog extends DialogFragment {
	private View root;
	CheAnhActivity anhActivity;
	ListView listView;
	String path = "";

	public static TrollSelectDialog newInstance(CheAnhActivity anhActivity) {
		TrollSelectDialog f = new TrollSelectDialog(anhActivity);
		return f;
	}

	public TrollSelectDialog(CheAnhActivity anhActivity) {
		this.anhActivity = anhActivity;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		path = anhActivity.pathTroll;
		initViewsSetting();
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle("Select Troll").setView(root).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
//				anhActivity.pathTroll = path;
//				anhActivity.previewImagetroll();
				dismiss();
			}
		}).create();
		return dialog;
	}

	private void initViewsSetting() {
		LayoutInflater inflater = LayoutInflater.from(getActivity());
		root = (ViewGroup) inflater.inflate(R.layout.cheanh_select_troll, null, false);
		listView = (ListView) root.findViewById(R.id.listView1);
		final String[] values = BaseEngine.getNamefileAsset(anhActivity, "");
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(anhActivity, android.R.layout.simple_list_item_1, android.R.id.text1, values);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				path = values[position];
				anhActivity.pathTroll = path;
				anhActivity.previewImagetroll();
				TrollSelectDialog.this.dismiss();
			}
		});
	}

}
